package remoto;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import dominio.RemitoProveedor;
import dto.RemitoProveedorTO;

public class GestionRemitosProveedor {
	private static GestionRemitosProveedor instance;

	public static GestionRemitosProveedor getInstance() throws MalformedURLException, RemoteException, NotBoundException {
		if (instance == null)
			instance = new GestionRemitosProveedor();
		return instance;
	}

	private IGestionRemitosProveedor remoto;

	private GestionRemitosProveedor() throws MalformedURLException, RemoteException, NotBoundException {
		remoto = (IGestionRemitosProveedor) Naming.lookup("GestionRemitosProveedor");
	}

	public int guardarRemitoProveedor(RemitoProveedor r) throws RemoteException {
		return remoto.guardarRemitoProveedor(r.getDTO());
	}

	public RemitoProveedor buscarRemitoProveedor(int id) throws RemoteException {
		RemitoProveedorTO dto = remoto.buscarRemitoProveedor(id);
		if (dto != null)
			return RemitoProveedor.fromDTO(dto);
		return null;
	}
}